package com.ying.workqueues;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * ClassName: SimpleProducer
 * Package: com.ying.workqueues
 * Description:
 *
 * @Author 刘英杰
 * @Create 2025/3/23 19:49
 * @Version 1.0
 */
public class WoekQueueProducer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.160.134");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("myHV");
        connectionFactory.setUsername("testUser");
        connectionFactory.setPassword("123456");

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("workQueue", true, false, false, null);

        for (int i = 0; i < 10; i++) {
            channel.basicPublish("","workQueue",null,("hello world" + i).getBytes());
        }

        //6.关闭channel和connection
        channel.close();
        connection.close();
    }
}
